package com.gao.security.autoconfig.bb;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.gao.security.verificationcode.code.VerificationCodeGenerationStrategy;
import com.gao.security.verificationcode.common.RequestPathType;
import com.gao.security.verificationcode.entity.VerificationCode;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 * @since 2019-08-01 10:55
 */
@Component
public class SmsVerificationCodeGenerationStrategy implements VerificationCodeGenerationStrategy {
    @Override
    public String createCode() {
        return "sms";
    }

    @Override
    public void sendCode(HttpServletRequest request, HttpServletResponse response, VerificationCode code) throws IOException {
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter printWriter = response.getWriter();
        ObjectMapper objectMapper =new ObjectMapper();
        printWriter.append(
                objectMapper.writeValueAsString(code));
    }

    @Override
    public VerificationCode check(HttpServletRequest request) {
        return null;
    }



    @Override
    public RequestPathType requestPathType() {
        return RequestPathType.SMS;
    }


}
